﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace autoBidProject
{
    public class Setting
    {
        public static string Url_Ibet="", Url_Sbo="";
        public static int TimeRefreshIBET = 200, TimeRefreshSBO = 200;  // miliseconds

        public static string xpath_live_ibet = "table/tbody/tr/td/table/tbody/tr/td/table/tbody/tr/td/table/tbody/tr[@class=\"GridItem\" or @class=\"GridRunItem\" or class=\"GridAltRunItem\"]";
        public static string xpath_nonlive_ibet = "table/tbody/tr/td/table/tbody/tr/td/table/tbody/tr/td/table/tbody/tr[@class=\"GridItem\" or @class=\"GridRunItem\" or class=\"GridAltRunItem\"]";

        public static bool bEventType;
        public static bool bGia0, bGia1, bGia2, bGia3;


        internal static bool LoadSetting()
        {
            try
            {
                XmlDocument xmldoc = new XmlDocument();
                xmldoc.Load("setting.ini");

                XmlNode root = xmldoc.DocumentElement;
                XmlNode node = root.SelectSingleNode("url");
                Url_Ibet = node.Attributes["ibet"].Value;
                Url_Sbo = node.Attributes["sbo"].Value;

                node = root.SelectSingleNode("refresh");
                TimeRefreshIBET = int.Parse(node.Attributes["ibet"].Value);
                TimeRefreshSBO = int.Parse(node.Attributes["sbo"].Value);

                node = root.SelectSingleNode("eventtype");
                string type = node.InnerText;
                if (type.ToLower() == "live")
                    bEventType = true;
                else
                    bEventType = false;

                bGia0 = bGia1 = bGia2 = bGia3 = true;

                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }


        public bool Save()
        {
            try
            {
                XmlTextWriter xtw = new XmlTextWriter("setting.ini", null);
                xtw.Formatting = Formatting.Indented;
                xtw.WriteStartDocument();

                xtw.WriteStartElement("url");
                xtw.WriteAttributeString("ibet", Url_Ibet);
                xtw.WriteAttributeString("sbo", Url_Sbo);
                xtw.WriteEndElement();

                xtw.WriteStartElement("refresh");
                xtw.WriteAttributeString("ibet", TimeRefreshIBET.ToString());
                xtw.WriteAttributeString("sbo", TimeRefreshSBO.ToString());
                xtw.WriteEndElement();

                xtw.WriteEndDocument();
                xtw.Flush();
                xtw.Close();
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
    }
}
